<?php
namespace Home\Controller;
use Think\Controller;
use Think\Exception;

class ProductController extends CommonController {
    public function index(){
        $data = array();
        $data['catid'] = $_GET['catid'];
        $data['status'] = 1;
        if ($_GET['material']){
        $data['material'] = $_GET['material'];
        }
        $page = $_REQUEST['p'] ? $_REQUEST['p'] : 1;
        $pageSize = 9;

        $pro = D("Product")->getproduct($data,$page,$pageSize);
        $count = D("Product")->getproductCount($data);

        $res  =  new \Think\Page($count,$pageSize);
        $pageres = $res->show();

        $set = D("Setting")->find($id = 1);
        $catid = $_GET['catid'];
		
		$catetitle = D("Category")->find($catid);
		$catetitle = $catetitle['catname'];
		

        $material = $_GET['material'];
        $this->assign('material',$material);
        $this->assign('catid',$catid);
		$this->assign('catetitle',$catetitle);
        $this->assign('pro',$pro);
        $this->assign('pageres',$pageres);
        $this->assign('set', $set);
        $this->display();
    }

    public function detail(){
        $id = $_GET['id'];
        $show = D("Product")->find($id);
        $set = D("Setting")->find($id = 1);
        $this->assign('set', $set);
        $this->assign('show',$show);
        $this->display();
    }

}